<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>购物车-{$tpshop_config['shop_info_store_title']}</title>
<meta http-equiv="keywords" content="{$tpshop_config['shop_info_store_keyword']}" />
<meta name="description" content="{$tpshop_config['shop_info_store_desc']}" />
<script src="__PUBLIC__/js/jquery-1.8.2.min.js"></script>
<script src="__PUBLIC__/js/global.js"></script>
<script src="__PUBLIC__/js/pc_common.js"></script>
<script src="__PUBLIC__/js/layer/layer.js"></script>
<link href="__STATIC__/css/common.min.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="__STATIC__/css/jh.css">
</head>
<body>
<include file="Public/sign-header"/>
<div class="fn-cart-confirm"> 
   <!-- cart-title -->
	  <div class="wrapper1190">
	     <div class="order-header">
	    	<div class="layout after">
	        	<div class="fl">
	            	<div class="logo pa-to-36 wi345">
	                	<a href="/"><img src="__STATIC__/images/newLogo.png" alt=""></a>
	                </div>
	            </div>
	        	<div class="fr">
	            	<div class="pa-to-36 progress-area">
	                	<div class="progress-area-wd" style="display:none">我的购物车</div>
	                	<div class="progress-area-tx">填写核对订单信息</div>
	                	<div class="progress-area-cg" style="display:none">成功提交订单</div>
	                </div>
	            </div>
	        </div>
	    </div>
	    <!-- end cart-title --> 
	     <!-- end收货信息 -->
		<form name="cart2_form" id="cart2_form" method="post">
		    <div class="layout be-table fo-fa ma-bo-45">
		    	<div class="con-info">
		        	<div class="con-y-info ma-bo-35">
		            	<h3>收货人信息<b>[<a href="javascript:void(0);" onClick="add_edit_address(0);">使用新地址</a>]</b></h3>
		                <div id="ajax_address"><!--ajax 返回收货地址--></div>                              
		            </div>
		        	<div class="con-y-info ma-bo-35 con-h">
		            	<h3>发票信息<em>(请谨慎选择发票抬头，订单出库后不能修改)</em></h3>
		                <div class="order-invoice-list">
		            		<ul>
		            		<li>
		                    	<div class="invoice-main fl"><label for="dw">发票抬头:</label></div>
		                        <div class="invoice-sub fl">
		                        	<label class="inv-label">
		                        		<input class="officdw" type="text" name="invoice_title" placeholder="XXX单位 或 XX个人" />
		                            </label>
		                        </div>
		                    </li>
		            	</ul>
		            	</div>
		                <p class="tips"><em>注意：</em>如果商品由第三方卖家销售，发票内容由其卖家决定，发票由卖家开具并寄出</p>
		            </div>					             
		        </div>
		        <div class="sc-area">
		        	<div class="dt-order-area">
		            	<div class="order-pro-list">
<!--商品列表-->
<foreach name="storeList" item="v">
		                	<div class="order-pro-list">
		                    	<div class="yxspy">
		                        	<div class="hv">{$v[store_name]}</div>
		                        	<div class="bv">
		                            	<table border="0" cellpadding="0" cellspacing="0">
		                                    <thead>
		                                        <tr>
		                                            <th class="tr-pro">商品</th>
		                                            <th class="tr-price">单价（元）</th>
		                                            <if condition="($user[discount] neq 1)">
		                                            	<th class="tr-price">会员折扣价</th>
		                                            </if>
		                                            <th class="tr-quantity">数量</th>
		                                            <th class="tr-subtotal">小计（元）</th>
		                                        </tr>
		                                    </thead>
		                                </table>
		                            </div>
		                        </div>                                
		                        <div class="leiliste">
		                        	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		                                <tbody>
		                                <foreach name="cartList" item="v2"  key="k">
										<if condition="($v2[selected] eq '1') and ($v2[store_id] eq $v[store_id])">
		                                    <tr>
		                                        <td class="tr-pro">
		                                            <ul class="pro-area-2">
		                                                <li>
		                                                  <a title="{$v2.goods_name}" target="_blank" href="{:U('Home/Goods/goodsInfo',array('id'=>$v2[goods_id]))}" seed="item-name">{$v2.goods_name}</a>
                                                           {$v2.spec_key_name} 
		                                                </li> 
		                                             </ul>
		                                         </td>
		                                        <!-- 预付订金商品的价格为空 -->
		                                        <td class="tr-price te-al">¥{$v2.goods_price}</td>
		                                        <if condition="($user[discount] neq 1)">
		                                        	<td class="tr-price te-al">¥{$v2.member_goods_price}</td>
		                                        </if>
		                                        <td class="tr-quantity te-al">{$v2.goods_num}</td>
		                                        <td rowspan="1" class="tr-subtotal te-al">
		                                        <p><b>￥{$v2.goods_fee}</b></p>
		                                        </td>
		                                    </tr>
											</if>
		                                </foreach>  
											<tr>
												<td colspan="4"><span class="span_ored">优惠券:</span>
                                                    <input type="radio" onclick="ajax_order_price();" value="1" checked="" name="couponTypeSelect[{$v[store_id]}]" class="radio vam ma-ri-10">
                                                    
                                                     <select onchange="ajax_order_price();" class="vam ou-no" name="coupon_id[{$v[store_id]}]">
                                                         <option value="0">选择优惠券</option>
                                                         <foreach name="couponList" item="v3">
					                                        <if condition="($v3[store_id] eq $v[store_id])">
		                                                         <option value="{$v3['id']}">{$v3['name']}</option>
                                                            </if>
                                                         </foreach>                                                         
                                                     </select>
                                                    &nbsp;&nbsp;&nbsp;
                                                    <input type="radio" onclick="ajax_order_price();" value="2" name="couponTypeSelect[{$v[store_id]}]" class="radio vam ma-ri-10">
                                                    <input type="text" placeholder="请输入优惠券代码" class="texter vam span-150 ma-ri-10 he18 li-he-18" name="couponCode[{$v[store_id]}]"> 
                                                    <input type="button" onclick="ajax_order_price();" value="使用" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam">
		                                        </td>                                                
                                                 <td rowspan="1" class="tr-subtotal te-al">
		                                     		   <p>-￥<b id="store_coupon_price_{$v[store_id]}">0</b></p>
		                                        </td>
		                                    </tr>  
                                            <tr>
	                                            <td colspan="4">
                                                <span class="span_ored">选择物流:</span>
                                                     <select onchange="ajax_order_price();" class="vam ou-no" name="shipping_code[{$v[store_id]}]">                                                                                                     
	                                                    <foreach name="shippingList" item="v4"  key="k4">
                                                            <if condition="$v4['store_id'] eq $v['store_id']">
                                                                 <option value="{$v4.shipping_code}">{$v4.name}</option>
                                                             </if>
    	                                                </foreach>
                                                     </select>                                                                                                    
                                                </td>
                                                 <td rowspan="1" class="tr-subtotal te-al">
		                                     		   <p>￥<b id="store_shipping_price_{$v[store_id]}">0</b></p>
		                                        </td>
                                            </tr>
											<tr>
	                                            <td colspan="4"><span class="span_ored">商家活动：</span></td>
                                                 <td rowspan="1" class="tr-subtotal te-al">
		                                     		   <p>-￥<b id="store_order_prom_amount_{$v[store_id]}">0</b></p>
		                                        </td>
                                            </tr>
											<tr>
	                                            <td colspan="4"><span class="span_ored">积分抵扣：</span></td>
                                                 <td rowspan="1" class="tr-subtotal te-al">
		                                     		   <p>-￥<b id="store_point_count_{$v[store_id]}">0</b></p>
		                                        </td>
                                            </tr>
											<tr>
	                                            <td colspan="4"><span class="span_ored">余额抵扣：</span></td>
                                                 <td rowspan="1" class="tr-subtotal te-al">
		                                     		   <p>-￥<b id="store_balance_{$v[store_id]}">0</b></p>
		                                        </td>
                                            </tr>                                                                                        
											<tr>
	                                            <td colspan="4"><span class="span_ored">店铺合计(含运费)：</span></td>
                                                 <td rowspan="1" class="tr-subtotal te-al">
		                                     		   <p>￥<b id="store_order_amount_{$v[store_id]}">0</b></p>
		                                        </td>
                                            </tr>                                                                                           
                                            <tr>
	                                            <td colspan="5">
                                                <span class="span_ored">给卖家留言:</span><input class="span_text texter" type="text" name="user_note[{$v[store_id]}]" value="" />                                                                                                                                         
                                                </td>
                                            </tr>                                            
		                                </tbody>
		                            </table>
		                        </div>
		                    </div>
<br/>                            
</foreach>                            
<!--商品列表 end-->                            
		                </div>
		                <div class="order-pro-total">
		                	<div class="fl wctmes">
		                        <div class="syyouhui pa-to-15">
		                        	<div class="duoxuk">
		                            	 <label class="fo-fa-ta" for="order-chick">使用优惠券:</label>&nbsp;&nbsp;注：优惠券每次只能使用一张，不可多张混合使用
		                       		</div>
		                            <div class="byicd">
		                            	<div class="zhiwfnka">
		                                    	<table border="0" cellpadding="0" cellspacing="0">
		                                            <tbody> 
		                                                <tr>
		                                                    <td>   
		                                                    <label class="fo-fa-ta" for="order-chick">积分支付:</label>                                                            
		                                                    <input type="text" id="pay_points" name="pay_points" class="texter vam span-150 ma-ri-10 he18 li-he-18" placeholder="请输入使用积分" onpaste="this.value=this.value.replace(/[^\d]/g,'')" onkeyup="this.value=this.value.replace(/[^\d]/g,'')"/>
		                                                    <input type="button" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam" value="使用" onClick="ajax_order_price();" />
		                                                    <?php echo tpCache('shopping.point_rate');?> 积分抵 1元 &nbsp;&nbsp;   您的可用积分 {$user['pay_points']} 分
		                                                    </td>
		                                                </tr>
		                                                <tr>
		                                                    <td>   
		                                                    <label class="fo-fa-ta" for="order-chick">余额支付:</label>
		                                                    <input type="text" id="user_money" name="user_money" class="texter vam span-150 ma-ri-10 he18 li-he-18" placeholder="请输入使用余额"  onpaste="this.value=this.value.replace(/[^\d\.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d\.]/g,'')"/>
		                                                    <input type="button" class="button-style-disabled-4 button-action-use-disabled te-al ou-no vam" value="使用" onClick="ajax_order_price();" />
		                                                    		您的可用余额 ¥ {$user['user_money']}
		                                                    </td>
		                                                </tr>                                                
		                                            </tbody>
		                                        </table>
		                                </div>
		                            </div>
		                        </div>                        
		                    </div>
		                    <div class="fr wcnhy">
		                    	<div class="fzoubddv">
		                        	<table width="100%" border="0" cellpadding="0" cellspacing="0">
		                                <tbody>
		                                    <tr>
		                                        <td class="tal">商品总金额：</td>
		                                        <td class="tar">&nbsp;¥&nbsp;
		                                           <em id="order-cost-area">{$total_price.total_fee}</em>
		                                        </td>
		                                    </tr>
		                                    <tr>
		                                        <td class="tal">运费：</td>
		                                        <td class="tar">&nbsp;¥&nbsp;
		                                               <em id="postFee">0.00</em> 
		                                        </td>
		                                    </tr>
		                                    <tr>
		                                        <td class="tal">使用优惠券：</td>
		                                        <td class="tar">-&nbsp;¥&nbsp;
		                                          <em><span id="couponFee">0.00</span> </em>
		                                        </td>
		                                    </tr>
		                                    <tr>
		                                        <td class="tal">使用积分：</td>
		                                        <td class="tar">-&nbsp;¥&nbsp;
		                                          <em><span id="pointsFee">0.00</span> </em>
		                                        </td>
		                                    </tr>
                                            <tr>
                                                <td class="tal">优惠活动：</td>
                                                <td class="tar">-&nbsp;¥&nbsp;
                                                  <em><span id="order_prom_amount">0.00</span> </em>
                                                </td>
                                            </tr>                                              
		                                    <tr>
		                                        <td class="tal">使用余额:</td>
		                                        <td class="tar">-&nbsp;¥&nbsp;
		                                          <em><span id="balance">0.00</span> </em>
		                                        </td>
		                                    </tr>                                    
		                                </tbody>
		                            </table>
		                            <p class="yifje-order">
		                            	<span class="p-subtotal-price"> 应付金额：
		                                    <b class="total">¥</b>
		                                    <b class="total" id="payables">0.00</b>
		                                </span>
		                            </p>
		                        </div>
		                    </div>
		                </div>
		            </div>
		            <div class="order-action-area te-al-ri">
		            	<div class="woypdbe sc-acti-list pa-to-20">
		                	<!--<span class="p-subtotal-price">应付总额：<b>¥<span class="vab" id="payableTotal">2276.00</span></b></span>-->
		                    <a class="Sub-orders gwc-qjs" href="javascript:void(0);" onClick="submit_order();"><span>提交订单</span></a>
		                </div>
		            </div>
		        </div>
		    </div>
		</form>    
    </div>
</div>

<!-- 提示切换省份 -->
<div id="changeProvince" style="display: none;">
          <div class="mask mask-cs-05 mask-4">
    <div class="mk-title">
              <h3>温馨提示</h3>
              <i data-x="1" class="mask-close-x changeAddrX"></i> </div>
    <div class="mk-adc">
              <div class="cs-01"> 您目前所在的省份为<strong>上海</strong>，选择<strong>安徽省</strong>的收货地址后，您购买的商品及价格将发生变化。 </div>
              <div class="cs-03">
        <button class="btn btn-red confirmChangeCity">切换省份</button>
        <button class="btn mask-close-x changeAddrX" data-x="1">取消</button>
      </div>
    </div>
  </div>
</div>
<!-- end 提示切换省份 --> 
<!-- 提示配送商品 -->
<div id="sorryTipLayer" style="display:none;">
    <div class="tipLayerCont">
    <p class="tip">对不起，以下商品暂时无法送达至<b>江苏省</b><b>无锡市</b><b>锡山区</b></p>
    <div class="tipLayerList">
              <div class="listHead"> <span class="name">商品名称</span> <span class="spec">规格</span> <span class="num">数量</span> <span class="price">金额</span> </div>
              <div class="listCont"> </div>
     </div>
  </div>
</div>
<!-- end 提示配送商品 --> 
<include file="Public/min-footer"/>
<script>
$(document).ready(function(){
	ajax_address(); // 获取用户收货地址列表
});
 
/**
* 新增修改收货地址
* id 为零 则为新增, 否则是修改
*  使用 公共的 layer 弹窗插件  参考官方手册 http://layer.layui.com/
*/
function add_edit_address(id)
{
	if(id > 0) 
		var url = "/index.php?m=Home&c=User&a=edit_address&scene=1&call_back=call_back_fun&id="+id; // 修改地址  '{:U('Home/User/add_address',array('scene'=>'1','call_back'=>'call_back_fun','id'=>id))}' //iframe的url /index.php/Home/User/add_address
	else
		var url = "/index.php?m=Home&c=User&a=add_address&scene=1&call_back=call_back_fun";	// 新增地址
	layer.open({
		type: 2,
		title: '添加收货地址',
		shadeClose: true,
		shade: 0.8,
		area: ['880px', '580px'],
		content: url,
	}); 	
} 
// 添加修改收货地址回调函数 
function call_back_fun(v){	 
	layer.closeAll(); // 关闭窗口
	ajax_address(); // 刷新收货地址	
}

// 删除收货地址
function del_address(id)
{
    if(!confirm("确定要删除吗?"))
	  return false;
	  
	  $.ajax({
		     url:"/index.php?m=Home&c=User&a=del_address&id="+id,
  			 success: function(data){
				ajax_address(); // 刷新收货地址							
			 }			 
	  });	  	  
}
 
/*
* ajax 获取当前用户的收货地址列表
*/
function ajax_address(){
	$.ajax({
		url:"{:U('Home/Cart/ajaxAddress')}",//+tab,
		success: function(data){
			$("#ajax_address").html('');
			$("#ajax_address").append(data);
			if(data != '') // 有收货地址列表 再计算价钱
				ajax_order_price(); // 计算订单价钱
		}
	});
}
 
// 切换收货地址
function swidth_address(obj)
{
        $(".order-address-list").removeClass('address_current');  
        $(obj).parent().parent().parent().parent().parent().addClass('address_current');
		ajax_order_price(); // 计算订单价格
}


// 获取订单价格
function ajax_order_price()
{

	$.ajax({
		type : "POST",
		url:"{:U('Home/Cart/cart3')}",//+tab,
		data : $('#cart2_form').serialize()+"&act=order_price",// 你的formid
        dataType: "json",
		success: function(data){
			
			if(data.status != 1)
			{ 
				layer.msg(data.msg, {
				  icon: 2,   // 成功图标
				  time: 1000 //2秒关闭（如果不配置，默认是3秒）
				});	
				// 登录超时
				if(data.status == -100) 
					location.href ="{:U('Home/User/login')}";
								
				return false;
			}
			// console.log(data);			
			$("#postFee").text(data.result.postFee); // 物流费
			$("#couponFee").text(data.result.couponFee);// 优惠券			
			$("#balance").text(data.result.balance);// 余额	
			$("#pointsFee").text(data.result.pointsFee);// 积分支付			
			$("#payables").text(data.result.payables);// 应付		
			$("#order_prom_amount").text(data.result.order_prom_amount);// 订单 优惠活动
			// 显示每个店铺的物流费
			for(v in data.result.store_shipping_price)			
				$('#store_shipping_price_'+v).text(data.result.store_shipping_price[v]);
			// 显示每个店铺的优惠券金额
			for(v in data.result.store_coupon_price)			
				$('#store_coupon_price_'+v).text(data.result.store_coupon_price[v]);
			// 显示每个店铺的积分
			for(v in data.result.store_point_count)			
				$('#store_point_count_'+v).text(data.result.store_point_count[v]/{$tpshop_config['shopping_point_rate']});
			// 显示每个店铺的余额抵扣
			for(v in data.result.store_balance)			
				$('#store_balance_'+v).text(data.result.store_balance[v]);				
			// 显示每个店铺订单优惠了多少钱
			for(v in data.result.store_order_prom_amount)			
				$('#store_order_prom_amount_'+v).text(data.result.store_order_prom_amount[v]);				
			// 显示每个店铺订单优惠后的价格
			for(v in data.result.store_order_amount)			
				$('#store_order_amount_'+v).text(data.result.store_order_amount[v]);				
		}
	});	
}

// 提交订单
ajax_return_status = 1; // 标识ajax 请求是否已经回来 可以进行下一次请求
function submit_order()
{
	if(ajax_return_status == 0)
	    return false;
		
	ajax_return_status = 0;	
		
	$.ajax({
		type : "POST",
		url:"{:U('Home/Cart/cart3')}",//+tab,
		data : $('#cart2_form').serialize()+"&act=submit_order",// 你的formid
        dataType: "json",
		success: function(data){
						
			if(data.status != '1')
			{
				// alert(data.msg); //执行有误
				//layer.alert(data.msg, {icon: 2});				
				layer.msg(data.msg, {
				  icon: 2,   // 成功图标
				  time: 1000 //2秒关闭（如果不配置，默认是3秒）
				});				
				// 登录超时
				if(data.status == -100) 
					location.href ="{:U('Home/User/login')}";
				
				ajax_return_status = 1; // 上一次ajax 已经返回, 可以进行下一次 ajax请
				
				return false;
			}
			// console.log(data);			
			$("#postFee").text(data.result.postFee); // 物流费
			$("#couponFee").text(data.result.couponFee);// 优惠券			
			$("#balance").text(data.result.balance);// 余额	
			$("#pointsFee").text(data.result.pointsFee);// 积分支付			
			$("#payables").text(data.result.payables);// 应付	
			$("#order_prom_amount").text(data.result.order_prom_amount);// 订单 优惠活动
			// 显示每个店铺的物流费
			for(v in data.result.store_shipping_price)			
				$('#store_shipping_price_'+v).text(data.result.store_shipping_price[v]);
			// 显示每个店铺的优惠券金额
			for(v in data.result.store_coupon_price)			
				$('#store_coupon_price_'+v).text(data.result.store_coupon_price[v]);
			// 显示每个店铺的积分
			for(v in data.result.store_point_count)			
				$('#store_point_count_'+v).text(data.result.store_point_count[v]/{$tpshop_config['shopping_point_rate']});
			// 显示每个店铺的余额抵扣
			for(v in data.result.store_balance)			
				$('#store_balance_'+v).text(data.result.store_balance[v]);				
			// 显示每个店铺订单优惠了多少钱
			for(v in data.result.store_order_prom_amount)			
				$('#store_order_prom_amount_'+v).text(data.result.store_order_prom_amount[v]);				
			// 显示每个店铺订单优惠后的价格
			for(v in data.result.store_order_amount)			
				$('#store_order_amount_'+v).text(data.result.store_order_amount[v]);		
 				
			//layer.alert('订单提交成功，跳转支付页面!', {icon: 1}); //alert('订单提交成功，跳转支付页面!');						
			layer.msg('订单提交成功，跳转支付页面!', {
			  icon: 1,   // 成功图标
			  time: 2000 //2秒关闭（如果不配置，默认是3秒）
			}, function(){ // 关闭后执行的函数
					location.href = "/index.php?m=Home&c=Cart&a=cart4&master_order_sn="+data.result; // 跳转到结算页
			});			
										
		}
	});	
}
</script>
</body>
</html>